<script>
import { RouterLink, RouterView } from "vue-router";
import { ref, reactive } from "vue";
import route from "./router";
export default {
  mounted() {
    this.initData();
    console.log(this.$route.path);
    
  },
  setup() {
    const userInfo = reactive({
      username: "",
      cname: "",
    });
    function initData() {
      let dataIofo = sessionStorage.getItem("userInfo");
      console.log(dataIofo);

      if (dataIofo) {
        dataIofo = JSON.parse(dataIofo);
        userInfo.username = dataIofo.userName;
        userInfo.cname = dataIofo.userName.slice(0, 1);
      }
    }

    return {
      userInfo,
      initData,
    };
  },
};
</script>

<template>
  <!-- <header>
    <img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />

    <div class="wrapper">
      <HelloWorld msg="You did it!" />

      <nav>
        <RouterLink to="/">Home</RouterLink>
        <RouterLink to="/about">About</RouterLink>
      </nav>
    </div>
  </header> -->
  <div class="user-info" v-if="userInfo.username && $route.path != '/login'">
    <div class="user-avatar">{{ userInfo.cname }}</div>
    <div class="user-name">{{ userInfo.username }}将军</div>
  </div>
  <RouterView />
</template>

<style>
* #app {
  margin: 0;
  padding: 0;
  
}

</style>
<style lang="less" scoped>
@media (max-width: 480px) {
  .menu-icon {
    font-size: 2.5rem;
  }

  .menu-text {
    font-size: 1.2rem;
  }

  .user-info {
    top: 10px;
    right: 10px;
    padding: 8px 12px;
  }

  .user-avatar {
    width: 30px;
    height: 30px;
    font-size: 1rem;
  }

  .user-name {
    font-size: 0.9rem;
  }
}
.user-info {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.9);
  padding: 10px 15px;
  border-radius: 30px;
  border: 1px solid #e0e0e0;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  z-index: 10;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #333;
  margin-right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.2rem;
}

.user-name {
  color: #333;
  font-size: 1.1rem;
  font-weight: 500;
}

</style>

